package com.zhoug.demo.push;

import android.app.Application;

import com.zhoug.common.utils.LogUtils;
import com.zhoug.logging.Logger;
import com.zhoug.push.imp.PushManager;
import com.zhoug.push.core.PushCallback;
import com.zhoug.push.core.PushConfig;
import com.zhoug.push.core.PushMessage;
import com.zhoug.push.core.PushVendor;

public class App extends Application {
    private static final String TAG = ">>>App";

    @Override
    public void onCreate() {
        super.onCreate();
        Logger.setDebug(true);
        LogUtils.setDebug(true);
        //获取PushManager单例
        PushManager pushManager = PushManager.getInstance();
        //初始化
        pushManager.init(this, new PushCallback() {
            @Override
            public void onTokenReceived(String token, String vendor) {
                //上传token到服务器和账号关联
                Logger.d(TAG, "onTokenReceived: vendor=" + vendor + ",token=" + token);
            }

            @Override
            public void onTokenRemoved(String vendor) {
                Logger.d(TAG, "onTokenRemoved: vendor=" + vendor);

            }

            @Override
            public void onTokenError(String vendor, int errorCode, String errorMessage) {
                Logger.d(TAG, "onTokenError: vendor=" + vendor + ",errorMessage=" + errorMessage);

            }

            @Override
            public void onMessageReceived(String vendor, PushMessage message) {
                //接受到消息,处理消息
                Logger.d(TAG, "onMessageReceived: vendor=" + vendor + ",message=" + message.getContent());
                String channelId = getPackageName() + "_todotask";
                AppNotificationManager.createNotificationChannel(getApplicationContext(), channelId, "待办任务");
                AppNotificationManager.sendNotification(getApplicationContext(), channelId, message);
            }
        });
        //获取当前推送平台
        String currentPushVendor = pushManager.getCurrentPushVendor();
        //配置推送appid等
        PushConfig pushConfig = new PushConfig();
        if (PushVendor.HUA_WEI.equals(currentPushVendor)) {
            pushConfig.setAppId("115795255");
        }
        //注册推送
        pushManager.registerPush(pushConfig);
    }

    public Application getApplication() {
        return this;
    }


}
